local skynet     = require "skynet"
local log        = require "bw.log"
local rankserver = require "sys.rank.server"
local ranktype   = require "sys.rank.type"
local def        = require "def.def"

local CMD = {}
function CMD.update(name, acc, data)
    rankserver.update(name, acc, data)
end

function CMD.request(name)
    local rank = rankserver.get_rank(name)
    if rank then
        return rank.obj.items
    else
        return {}
    end
end

rankserver.start(CMD, function()
    for _, v in pairs(def.Rank.SAMPLE) do
        rankserver.load_rank(v.name, v.type, v.count, function(a, b)
            return a.v.score > b.v.score
        end)

        -- 测试数据
        local rank = rankserver.get_rank(v.name)
        for i = #rank.obj.items, 20 do
            rank:update("acc"..i, {
                nickName = "test"..i,
                avatarUrl = "",
                score = math.random(1000),
            })
        end
    end
end)
